﻿-- =============================================
-- Author:		<赵洪涛>
-- Create date: <2013-11-12>
-- Description:	<根据成单编号查找相关员工>
-- =============================================
CREATE PROCEDURE [dbo].[proc_WebService_CheckOrderByUserId]
(
	@UserId varchar(20),
	@OrderId uniqueidentifier
)
AS
BEGIN
	;WITH List As(
		SELECT [SalesmanAccount] As UID	--报备人
		FROM [Order]
		Where OId=@OrderId
		Union All
		SELECT [GenJinKfAccount] As UID	--跟进客服
		FROM [Order]
		Where OId=@OrderId
		Union All
		SELECT [TrackKfAccount] As UID	--综合/维护客服
		FROM [Order]
		Where OId=@OrderId
		Union All
		SELECT [DownPerson] As UID	--下发任务的人
		FROM [Project_Task]
		where orderid=@OrderId
		Union All
		SELECT [ExecPerson] As UID	--执行任务的人
		FROM [Project_Task]
		where orderid=@OrderId
	)

	Select Count(0) As shl From List Where UID=@UserId
END
